#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
int n,c,b[N],num[N],cnt,cou,cc,cx[N],sk,ct,si[N];ll as[N];
vector<int>a[500005];
struct node
{
    int i,j,len;
    bool operator<(const node&y)const{return len<y.len;}
}v[N];
int main()
{
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1,ki;i<=n;++i)
    {
        cin>>ki;a[i]=vector<int>(ki);sk+=ki;
        for(int j=0;j<ki;++j)cin>>a[i][j],num[++cnt]=a[i][j];
    }
    cin>>c;
    for(int i=1;i<=n;++i)cin>>b[i];
    sort(num+1,num+1+cnt);
    cnt=unique(num+1,num+1+cnt)-num-1;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<a[i].size();++j)
        {
            int pos=lower_bound(num+1,num+cnt+1,a[i][j])-num;
            si[pos]++;
            if(j)v[++cou]={i,j,a[i][j]-a[i][j-1]+1};
        }
    }
    ll ss=0;
    for(int i=1;i<=cnt;++i)ss+=1ll*b[si[i]]*si[i];
    sort(v+1,v+cou+1);v[cou+1]={-1,-1,2000000000};
    memset(as,-1,sizeof(as));
    ll ans=ss+1ll*c*sk;as[0]=ans;
    for(int i=1;i<=cou;++i)
    {
        int pos=lower_bound(num+1,num+cnt+1,a[v[i].i][v[i].j])-num;
        ss-=1ll*b[si[pos]]*si[pos];
        si[pos]--;ss+=1ll*b[si[pos]]*si[pos];
        ss+=1ll*c*(v[i].len-1);sk--;
        if(v[i].len!=v[i+1].len)ans=min(ans,(as[i]=ss+1ll*c*sk*(v[i].len)));
    }
    if(as[0]==ans)cx[++cc]=1;
    for(int i=1;i<=cou;++i)if(as[i]==ans)cx[++cc]=v[i].len;
    cout<<ans<<" "<<cc<<"\n";
    for(int i=1;i<=cc;++i)cout<<cx[i]<<" ";
    return 0;
}